package com.neusoft.mapper;

import com.neusoft.po.Redenv;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface RedenvMapper {

    /*
    @Select("select * from remark where businessId=#{businessId}")
    public List<Redenv> listRemarksByBussinessId(Integer businessId);

    @Insert("insert into remark(remark,userId,userName,businessId,remarkDate) values(#{remark},#{userId},#{userName},#{businessId},#{remarkDate})")
    @Options(useGeneratedKeys = true, keyProperty = "remarkId", keyColumn = "remarkId")
    public int saveRemarks(Redenv redenv);

    //删除某用户所有评论
    @Select("delete from remark where userId=#{userId}")
    public List<Redenv> removeAllRemarksByUserId(String userId);

    //删除某用户某条评论
    @Select("delete from remark where userId=#{userId} and remarkId=#{remarkId} " )
    public List<Redenv> removeOneRemarksByUserId(String userId, Integer remarkId);
    */

    //根据userId生成一个红包
    @Insert("insert into redenv(redenvId,userId,balance,state) values(null,#{userId},#{balance},0)")
    public int saveOneRedenvByUserId(@Param("userId") String userId, @Param("balance") BigDecimal balance);

    //根据userId查询所有可用红包
    @Select("select * from redenv where userId=#{userId} and state=0")
    public List<Redenv> getAllRedenvsByUserId(@Param("userId")String userId);

    @Update("update redenv set state=1 where redenvId=#{redenvId}")
    public Integer useRedenvByRedenvId(@Param("redenvId")Integer redenvId);

    @Select("select * from redenv where redenvId=#{redenvId}")
    public Redenv getRedenvByRedenvId(@Param("redenvId")Integer redenvId);
}
